package com.itcodai.controller.course10;

import com.itcodai.entity.User;
import com.itcodai.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author c-fanqj
 * @date 2023/3/25
 * @apiNote
 */
@RestController
@RequestMapping("/user")
@Api(value = "MyBatis基本操作")
public class MyBatisTestController {

    @Resource
    private UserService userService;

    @GetMapping("/getUser/{id}")
    @ApiOperation(value = "根据用户标识获取用户信息")
    public User getUser(
            @PathVariable @ApiParam(value = "用户唯一标识") Long id) {
        return userService.getUser(id);
    }

    @GetMapping("/getUser/{id}/{name}")
    @ApiOperation(value = "根据用户标识和名称获取用户信息")
    public User getUser(
            @PathVariable @ApiParam(value = "用户唯一标识") Long id,
            @PathVariable @ApiParam(value = "用户唯一名称") String name) {
        return userService.getUser(id, name);
    }

    @GetMapping("/getall")
    @ApiOperation(value = "获取用户信息列表")
    public List<User> getAll() {
        return userService.getAll();
    }

    @GetMapping("/getUserByName/{name}")
    @ApiOperation(value = "根据用户名称获取用户信息")
    public User getUserByName(
            @PathVariable @ApiParam(value = "用户唯一名称") String name) {
        return userService.getUserByName(name);
    }

}
